package com.example.demo2.student;
import com.example.demo2.pojo.course;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddKecheng")
public class AddKecheng extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		KechengDaoImp daoImo = new KechengDaoImp();
		String name = request.getParameter("name");
		int credit =Integer.parseInt(request.getParameter("credit"));
		course course = new course();
		course.setName(name);
		course.setCredit(credit);
		course.setTeacher("还未实现老师端");
		daoImo.insert(course);
		request.setAttribute("list", daoImo.selectAll());
		request.getRequestDispatcher("/FindAllKechnegName").forward(request, response);
	}

}
